/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package group2assignone.view.manager;

import group2assignone.model.Flight;
import group2assignone.view.OurView;
import group2assignone.view.UITool;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 *
 * @author Brad
 */
public class AddPromotionView extends OurView {

    private JButton search = new JButton("Search");
    private JButton cancel = new JButton("Cancel");
    private JButton addPromotion = new JButton("Add");
    private JButton save = new JButton("Save");

    private JLabel title = new JLabel("Add Promotion");
    private JLabel flightNum = new JLabel();
    private JLabel depLoc = new JLabel();
    private JLabel depTime = new JLabel();
    private JLabel arrLoc = new JLabel();
    private JLabel arrTime = new JLabel();
    private JLabel seatCap = new JLabel();
    private JLabel date = new JLabel();
    private JLabel flightNumLabel = new JLabel("Enter Flight Number:");
    private JLabel cost = new JLabel();
    private JLabel promotion = new JLabel("Promotion Amount (%)");
    private JTextField fnum = new JTextField(5);
    private JTextField promoField = new JTextField(3);
    private Flight flt;


    public Flight LoadDetails() {
        flt.setPromotion(Integer.parseInt(promoField.getText()));
        System.out.println("in addpromotionView.  promofield is : "+ promoField.getText() );
        return flt;
    }

    /**
     *
     * @param al
     */
    public void setSearchAL(ActionListener al) {
        search.addActionListener(al);
    }

    /**
     *
     * @param al
     */
    public void setCancelAL(ActionListener al) {
        cancel.addActionListener(al);
    }

    /**
     *
     * @param al
     */
    public void setSaveAL(ActionListener al) {
        save.addActionListener(al);
    }

    /**
     *
     * @param al
     */
    public void setAddPromotionAL(ActionListener al) {
        addPromotion.addActionListener(al);
    }

    /**
     *
     * @param al
     */
    public void addPromotionToFlight(Flight f) {
        f.setPromotion(Integer.parseInt(promoField.getText()));
    }

    public void errorFlightNum() {
        UITool.displayError("Invalid Flight Number.  Please re-enter.", this);
        resetFlightNum();
    }

    public String getFlightNum() {
        return fnum.getText();
        
    }

    public void resetFlightNum() {
        fnum.setText("");
    }

    @Override
    public void addComponents() {
        southPanel.add(search);
        southPanel.add(cancel);
        centerPanel.add(flightNumLabel);
        centerPanel.add(fnum);

        pack();
    }

    public void clearShowFlightWindow() {
        westPanel.removeAll();
        eastPanel.removeAll();
        southPanel.removeAll();
    //remove(westPanel);
    //remove(eastPanel);
    }

    public void clearFlightNumWindow() {
        remove(centerPanel);
        southPanel.removeAll();
    }

    public void showFlightDetails(Flight f) {
        clearFlightNumWindow();
        flt = f;
        //Initialise components
//GridLayout(int rows, int cols, int hgap, int vgap)
        eastPanel.setLayout(new GridLayout(5, 1, 2, 1));
        westPanel.setLayout(new GridLayout(5, 1, 2, 1));

        flightNum.setText("Flight Number: " + flt.getFlightNum());
        depLoc.setText("Departure Location: " + flt.getDepLoc());
        arrLoc.setText("Arrival Location: " + flt.getArrLoc());
        seatCap.setText("Seating Capacity: " + flt.getSeatCap()); //turn seatcap into string
        date.setText("Date: " + flt.getDate());
        depTime.setText("Departure Time: " + flt.getDepTime());
        arrTime.setText("Arrival Time: " + flt.getArrTime());

        westPanel.add(flightNum);
        westPanel.add(depLoc);
        westPanel.add(arrLoc);
        westPanel.add(seatCap);
        westPanel.add(promotion);

        eastPanel.add(date);
        eastPanel.add(depTime);
        eastPanel.add(arrTime);
        eastPanel.add(cost);
        eastPanel.add(promoField);

        eastPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 10));
        westPanel.setBorder(BorderFactory.createEmptyBorder(2, 10, 2, 2));

        southPanel.add(save);
        southPanel.add(cancel);

        pack();
    }
}
